<template>
  <div class="box">
    <div class="allbox loginallbox">
      <div class="tag_box">
        <div class="tab">{{ this.$route.meta.title }}</div>
      </div>
      <div class="login_box_gr">
        <div class="login_box_gr_input">
          <div class="login_title">{{ this.$route.meta.title }}</div>
          <el-input placeholder="请输入登录账号" v-model="form.account">
            <template slot="prepend">账号：</template>
          </el-input>
          <el-input
            show-password
            placeholder="请输入密码"
            v-model="form.password"
          >
            <template slot="prepend">密码：</template>
          </el-input>
          <div class="delu" @click="grlogin()">登录</div>
          <div class="tishi_login">
            <div>
              没有账号，去
              <router-link to="grzc"
                ><span class="tz">注册非执业会员</span></router-link
              >
            </div>
            <div>
              <router-link to="grwjmm"
                ><span class="tz">忘记密码？</span></router-link
              >
            </div>
          </div>
          <div class="bottom_login">
            登录账号为：手机号、邮箱、姓名
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
  
  <script>
export default {
  data() {
    return {
      form: {
        account: "",
        password: "",
      },
    };
  },
  mounted() {
    if (this.$route.query.path == "login") {
      let token = "";
      let url = "";
      if (localStorage.getItem("jgtoken")) {
        token = localStorage.getItem("jgtoken");
        url = "/indexhy";
      }
      if (localStorage.getItem("grtoken")) {
        token = localStorage.getItem("grtoken");
        url = "/indexgr";
      }
      if (localStorage.getItem("zjtoken")) {
        token = localStorage.getItem("zjtoken");
        url = "/indexzj";
      }
      if (token) {
        this.$router.push({ path: url });
      }
    }
  },
  methods: {
    /**
     * 登录
     */
    grlogin() {
      let that = this;
      let data = that.form;
      // console.log(JSON.stringify(data))
      that.$http.post("user/login", data).then((res) => {
        that.$self.ts(res, 3).then((e) => {
          // console.log(e);
          localStorage.clear();

          localStorage.setItem("grtoken", res.data.userinfo.token);
          that.$http.post("user/user_info", {}).then((ret) => {
            localStorage.setItem("info", JSON.stringify(ret.data));
            this.$router.push({ path: "/indexgr" });
          });
        });
      });
    },
    //  ==
  },
};
</script>
  <style scoped>
  ::v-deep .el-input-group__prepend{
  width: 0.9rem;
  color: #333;
}

</style>